package servlet.login;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import beans.Customer;
import service.CustomerService;

@WebServlet("/RegisterServlet")
public class RegisterServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    
    public RegisterServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		CustomerService service = new CustomerService();
		
		String username = request.getParameter("username");
		String sex = request.getParameter("sex");
		String tel = request.getParameter("tel");
		String addr = request.getParameter("addr");
		String money = "0";
		String school = request.getParameter("school");
		String wechat = request.getParameter("wechat");
		Customer registerUser = service.registerUser(username, sex, tel, addr, money, school, wechat);
		request.getSession().setAttribute("customer", registerUser);
		response.sendRedirect(request.getContextPath() + "/index.html");
	}

}
